package com.fh.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.fh.mapper.RoleMapper;
import com.fh.model.Role;
import com.fh.service.RoleService;
import com.fh.util.DataTablePageUtil;
import com.fh.vo.RoleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleMapper roleMapper;
    @Override
    public DataTablePageUtil<Role> queryRole(DataTablePageUtil<Role> page, RoleVo roleVo) {
        //将条件查询放入json中
        JSONObject json = (JSONObject)JSONObject.toJSON(roleVo);
        //这是求分页的下标
        json.put("start",page.getStart());
        json.put("length",page.getLength());
        //查询数据
        List<Role> roles = roleMapper.queryRole(json);
        //查询数据个数
        Integer count = roleMapper.queryCount();
        page.setData(roles);
        page.setRecordsTotal(count);
        page.setRecordsFiltered(count);
        return page;
    }

    @Override
    public void addRole(Role role) {
        roleMapper.addRole(role);
    }

    @Override
    public Role toUpdateRole(Integer roleId) {
        return roleMapper.toUpdateRole(roleId);
    }

    @Override
    public void updateRole(Role role) {
        roleMapper.updateRole(role);
    }

    @Override
    public void deleteRole(Integer roleId) {
        roleMapper.deleteRole(roleId);
    }

    @Override
    public void deleteBothRole(Integer[] arr) {
        roleMapper.deleteBothRole(arr);
    }
}
